/*
 * @Author: NtyAaron
 * @Date: 2021-04-12 11:13:45
 * @LastEditors: NtyAaron
 * @LastEditTime: 2021-05-06 11:10:31
 * @Description: file content
 * @FilePath: \dwq\pages\support\support.js
 */

import { getHelpList, getHelp } from '../../api/support/support'
import { _t, _type } from '../../i18n/base'
Page({
  data: {
    active: 0,
    activeNames: [],
    helpList: [],
    objReq: {
      // language: 1,
      type: 1,
    },
  },
  // 切换标签
  onChange({ detail }) {
    this.setData({
      ['objReq.type']: detail.name + 1,
      activeNames: [],
    })
    this.getHelpList(this.data.objReq)
  },
  // 折叠面板
  async collChangeHandle({ detail }) {
    if (detail != '') {
      this.setData({
        activeNames: detail,
      })
    } else {
      this.setData({
        activeNames: [],
      })
    }
  },
  // 获取帮助界面列表
  async getHelpList(e) {
    e.language = this.data.language
    this.setData({
      helpList: [],
    })
    let { result } = await getHelpList(e)
    this.setData({
      helpList: result,
    })
  },
  // 跳转详情页
  toDetail(e) {
    let id = e.currentTarget.dataset.helpid
    wx.navigateTo({
      url: `/pages/supportDetail/supportDetail?helpId=${id}`,
    })
  },
  initLoginStatus() {
    let userId = wx.getStorageSync('userId')
    if (!userId) {
      wx.switchTab({
        url: '/pages/index/index',
      })
    }
  },
  onLoad() {
    this.setData({
      lang: _t(),
      language: _type(),
    })
    wx.setNavigationBarTitle({
      title: this.data.lang['帮助'],
    })
  },
  onShow() {
    this.getHelpList(this.data.objReq)
    // this.initLoginStatus()
  },
})
